<?php

namespace app\company\model;


use think\Model;

/**
 * @property  int $id
 * @property  int $company_id 公司id
 * @property  string $name 司机姓名
 * @property  string $mobile 手机号
 * @property  string $id_card 身份证号
 * @property  string $no 编号
 * @property  string $password 密码
 */
class DeliverDriver extends Base
{


    public static function onBeforeInsert(DeliverDriver $model): void
    {
        $model->company_id = getCompanyId();
        $model->password   = md5($model->password . 'dt');
    }


    public static function onAfterInsert(DeliverDriver $model): void
    {
        $model->no = "SJ" . date("Ymd") . str_pad($model->id, 4, '0', STR_PAD_LEFT);
        $model->save();
    }


    public static function onBeforeUpdate(DeliverDriver $model): void
    {
        if(request()->param('password',0)) $model->password = md5($model->password . 'dt');
    }
}